    package com.boot.springboot.controller;


    import com.boot.springboot.pojo.ResponseMessage;
    import com.boot.springboot.pojo.Good;
    import com.boot.springboot.pojo.dto.GoodDto;
    import com.boot.springboot.service.IGoodService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.validation.annotation.Validated;
    import org.springframework.web.bind.annotation.*;

    import java.util.List;

    @RestController//接口方法返回对象，装换成json文本
    @RequestMapping("/good") //默认地址
    public class GoodController {
        @Autowired
        IGoodService goodService;
        //增加商品
        @PostMapping
        public ResponseMessage<Good> add(@Validated @RequestBody /*@Validated验证对象数据是否符合要求，@RequestBody接收 HTTP 请求体中的数据并将其绑定到方法参数*/ GoodDto good){
            Good goodNew=goodService.add(good);
            return ResponseMessage.success(goodNew);
        }

        //查询商品
        @GetMapping("/{goodId}")
        public ResponseMessage<Good> get(@PathVariable Integer goodId){
            Good goodNew=goodService.get(goodId);
            return ResponseMessage.success(goodNew);
        }


        //修改商品
        @PutMapping
        public ResponseMessage<Good> edit(@Validated @RequestBody /*@Validated验证对象数据是否符合要求，@RequestBody接收 HTTP 请求体中的数据并将其绑定到方法参数*/  GoodDto good){
            Good goodNew=goodService.edit(good);
            return ResponseMessage.success(goodNew);
        }


        //删除商品
        @DeleteMapping("/{goodId}")
        public ResponseMessage<Good> delete(@PathVariable Integer goodId){
            goodService.delete(goodId);
            return ResponseMessage.delete();
        }
        //查询所有商品数据
        @GetMapping
        public ResponseMessage<List<Good>> getAllGoods(){
            List<Good> goods=goodService. getAllGoods();
            return ResponseMessage.success(goods);
        }

    }
